package com.whfc.fse.queue;

import com.alibaba.fastjson.JSON;
import com.whfc.common.constant.QueueConst;
import com.whfc.fse.dto.FseGantryDataDTO;
import com.whfc.fse.manager.FseGantryMgr;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * 处理龙门吊同步的实时数据
 *
 * @author sun_guodong
 * @date 2020-05-26
 */
@Component
@RabbitListener(queuesToDeclare = {@Queue(name = QueueConst.FSE_GANTRY_CURRENT_DATA)}, concurrency = "1-2",containerFactory = "baseFactory")
public class FseGantryRealDataQueueListener {
    private static final Logger logger = LoggerFactory.getLogger(FseGantryRealDataQueueListener.class);

    @Autowired
    private FseGantryMgr fseGantryMgr;

    @RabbitHandler
    public void handle(String msg) {
        logger.info("队列同步龙门吊实时数据,msg:{}", msg);
        try {
            FseGantryDataDTO fseGantryData = JSON.parseObject(msg, FseGantryDataDTO.class);
            fseGantryMgr.addData(fseGantryData);
        } catch (Exception e) {
            logger.error("队列同步龙门吊实时数据出错", e);
        }
    }

}
